CQCIS.grid.PagingToolbar = function(config) {
    Ext.apply(this, config);
    CQCIS.form.DWRForm.superclass.constructor.call(this);
};

Ext.extend(CQCIS.grid.PagingToolbar, Ext.PagingToolbar, {
    firstText: "第一页 (<b>ctrl + Home</b>)",
    prevText: "前一页 (<b>alt + &lt;</b>)",
    nextText: "下一页 (<b>alt + &gt;</b>)",
    lastText: "最后页 (<b>ctrl + End</b>)",
    refreshText: "刷新",
    beforePageText: "第",
    afterPageText: "页, 共{0}页",
    displayMsg: '显示 {0}-{1}, 共 {2} 条',
    emptyMsg: "没有符合条件的记录",
    displayInfo: true,
    onRender: function(ct, position) {
        Ext.PagingToolbar.superclass.onRender.call(this, ct, position);
        this.first = this.addButton({
            tooltip: this.firstText,
            iconCls: "x-tbar-page-first",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["first"])
        });
        this.prev = this.addButton({
            tooltip: this.prevText,
            iconCls: "x-tbar-page-prev",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["prev"])
        });
        this.addSeparator();
        this.add(this.beforePageText);
        this.field = Ext.get(this.addDom({
            tag: "input",
            type: "text",
            size: "3",
            value: "1",
            cls: "x-tbar-page-number"
        }).el);
        this.field.on("keydown", this.onPagingKeydown, this);
        this.field.on("focus", function() {
            this.dom.select();
        });
        this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
        this.field.setHeight(18);
        this.addSeparator();
        this.next = this.addButton({
            tooltip: this.nextText,
            iconCls: "x-tbar-page-next",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["next"])
        });
        this.last = this.addButton({
            tooltip: this.lastText,
            iconCls: "x-tbar-page-last",
            disabled: true,
            handler: this.onClick.createDelegate(this, ["last"])
        });
        this.addSeparator();
        this.loading = this.addButton({
            text: '刷新',
            disabled: true,
            tooltip: this.refreshText,
            iconCls: "btn_refresh",
            handler: this.onClick.createDelegate(this, ["refresh"])
        });
        
        if (this.displayInfo) {
            this.displayEl = Ext.fly(this.el.dom).createChild({
                cls: 'x-paging-info'
            });
        }
        if (this.dsLoaded) {
            this.onLoad.apply(this, this.dsLoaded);
        }
    },
    extendFun: function() {
        var store = new Ext.data.SimpleStore({
            fields: ['pageSize'],
            data: [[10], [20], [25], [30], [40], [50], [60], [80], [100]]
        });
        var combo = new Ext.form.ComboBox({
            store: store,
            displayField: 'pageSize',
            editable: false,
            typeAhead: false,
            mode: 'local',
            value: this.pageSize,
            triggerAction: 'all',
            selectOnFocus: true,
            disabled: true,
            width: 45,
            listWidth: 45
        });
        this.pageSizeCombo = combo;
        
        var pageNo = this.field;
        this.add('-', '页大小', combo);
        
        this.field.set({
            disabled: true
        });
        combo.on("select", function(c, record) {
            this.pageSize = parseInt(c.getValue(), 10);
            this.doLoad(0);
        }, this);
        this.store.on('load', function() {
            combo.setDisabled(this.store.getCount() === 0);
            this.field.set({
                disabled: this.store.getCount() === 0
            });
            //this.loading.setDisabled(this.store.getCount() == 0);
        }, this);
        
        this.first.KeyMap = new Ext.KeyMap(document, {
            key: 36,
            //alt : true,
            ctrl: true,
            fn: this.onClick.createDelegate(this, ["first"])
        });
        this.last.KeyMap = new Ext.KeyMap(document, {
            key: 35,
            //alt : true,
            ctrl: true,
            fn: this.onClick.createDelegate(this, ["last"])
        });
        this.prev.KeyMap = new Ext.KeyMap(document, {
            key: 188,
            alt: true,
            //ctrl : true,
            fn: this.onClick.createDelegate(this, ["prev"])
        });
        this.next.KeyMap = new Ext.KeyMap(document, {
            key: 190,
            alt: true,
            //ctrl : true,
            fn: this.onClick.createDelegate(this, ["next"])
        });
        this.loading.KeyMap = new Ext.KeyMap(document, {
            key: 'R',
            alt: true,
            //ctrl : true,
            fn: this.onClick.createDelegate(this, ["refresh"])
        });
    }
});
